//package com.pug.order.config;
//
//import com.pug.order.nacos.RgsNacosClusterNameRoute;
//import com.pug.order.nacos.RgsNacosWeightRoute;
//import org.springframework.beans.factory.ObjectProvider;
//import org.springframework.cloud.client.ServiceInstance;
//import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
//import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
//import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer;
//import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
//import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.core.env.Environment;
//
///**
// * @program: xq_pug_alibabacloud_parent
// * @description: 自定义负载规则
// * @author: Mr.Ren
// * @create: 2023-04-16 22:01
// **/
//@LoadBalancerClients({
//        @LoadBalancerClient(value = "user-service", configuration = UserRandomLoadBalancerConfig.class),
//        @LoadBalancerClient(value = "product-service", configuration = ProductRandomLoadBalancerConfig.class)
//})
//public class CustomRibbonConfig {
//}
//
//class UserRandomLoadBalancerConfig {
//
//    @Bean
//    public ReactorLoadBalancer<ServiceInstance> reactorServiceInstanceLoadBalancer(Environment environment, LoadBalancerClientFactory factory) {
//        //获取服务实例名称（user-service）
//        String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
//
//        //获取当前服务注册信息的nacos实例列表
//        ObjectProvider<ServiceInstanceListSupplier> lazyProvider = factory.getLazyProvider(name, ServiceInstanceListSupplier.class);
//
//        //选择负载均衡策略，这里我们选择我们自定义的按照城市名称负载策略
//        //return new RgsNacosClusterNameRoute(lazyProvider, name);
//        //基于权重的负载规则
//        return new RgsNacosWeightRoute(lazyProvider,name);
//    }
//}
//
//class ProductRandomLoadBalancerConfig {
//
//    @Bean
//    public ReactorLoadBalancer<ServiceInstance> reactorServiceInstanceLoadBalancer(Environment environment, LoadBalancerClientFactory factory) {
//        String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
//
//        ObjectProvider<ServiceInstanceListSupplier> lazyProvider = factory.getLazyProvider(name, ServiceInstanceListSupplier.class);
//
//        return new RgsNacosClusterNameRoute(lazyProvider, name);
//    }
//}
//
//
//
